#include "biblereaderprojectdialog.h"
#include <QGridLayout>
#include <QTextCharFormat>
#include "Logger.h"
#include "ConsoleAppender.h"

BibleReaderProjectDialog::BibleReaderProjectDialog(BibleReaderCore *brc,
                                                   QString text,
                                                   QWidget *parent)
    :QDialog(parent)
{
    brCore = brc;
    connect(brCore->getConfigurator(), SIGNAL(projectDlgBGChanged(QColor)), this,
            SLOT(setBgColor(QColor)));
    connect(brCore->getConfigurator(), SIGNAL(projectDlgFGChanged(QColor)), this,
            SLOT(setFgColor(QColor)));

    setWindowFlags(Qt::Window);
    bgColorQSS = "QTextBrowser#projectcontent {background-color: %1; border:0px; }";

    panel = new QTextBrowser(this);
    panel->setObjectName("projectcontent");
    panel->setWindowFlags(Qt::FramelessWindowHint);
    panel->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

    versesText = text;

    QGridLayout *layout = new QGridLayout(this);
    layout->setContentsMargins(0, 0, 0, 0);
    layout->addWidget(panel);
    setLayout(layout);

}

BibleReaderProjectDialog::~BibleReaderProjectDialog()
{
    delete panel;
}

QColor BibleReaderProjectDialog::getBgColor() const
{
    return bgColor;
}

void BibleReaderProjectDialog::setBgColor(const QColor value)
{
    bgColor = value;

    setStyleSheet(bgColorQSS.arg(value.name()));
}

QColor BibleReaderProjectDialog::getFgColor() const
{
    return fgColor;
}

void BibleReaderProjectDialog::setFgColor(const QColor value)
{
    fgColor = value;
}

QString BibleReaderProjectDialog::showVerseText()
{
    LOG_INFO() << QString::number(brCore->getConfigurator()->getPrjTextFontSize())
               << brCore->getConfigurator()->getPrjTextFontFamily();
    QString t = QString("<span style='font-size: %1pt; color: %2;font-family:%3'>%4</span>");
    panel->setText(t.arg(QString::number(brCore->getConfigurator()->getPrjTextFontSize()),
                         fgColor.name(),
                         brCore->getConfigurator()->getPrjTextFontFamily(),
                         versesText));
    showFullScreen();

    return t;
}

